package com.xinsoft.controller.device;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.CusGateWayParam;
import com.xinsoft.entity.po.CusGateway;
import com.xinsoft.service.CusGatewayService;
import com.xinsoft.utils.ExcelUtils;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName CusGateWayController
 * @Description 网关管理
 * @Author lijie
 * @Date 2023-6-13 12:53:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/cus/gateWay")
@Api(value = "CusGateWayController", tags = {"网关管理控制层"})
public class CusGateWayController {
	@Autowired
	private CusGatewayService gatewayService;

	/**
	 * @Author Li9527
	 * @Description 网关管理-新增
	 * @Date 2023/5/17 9:57
	 * @params   dept
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("新增")
	@PostMapping("/add")
	public Response<?> add(@RequestBody CusGateway cusGateway) {
		// 参数校验
		ValidatorUtils.validateEntity(cusGateway);
		return Response.succeed(gatewayService.save(cusGateway));
	}

	/**
	 * @Author Li9527
	 * @Description 更新
	 * @Date 2023/5/17 9:57
	 * @params   dept
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("更新")
	@PostMapping("/edit")
	public Response<?> edit(@RequestBody CusGateway cusGateway) {
		// 参数校验
		ValidatorUtils.validateEntity(cusGateway);
		return Response.succeed(gatewayService.updateById(cusGateway));
	}

	/**
	 * @Author Li9527
	 * @Description 删除
	 * @Date 2023/5/12 9:20
	 * @params   ids
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("删除")
	@PostMapping("/del")
	public Response<?> del(@RequestBody List<Integer> ids) {
		gatewayService.removeByIds(ids);
		return Response.succeed();
	}

	/**
	 * @Author Li9527
	 * @Description 网关管理控分页
	 * @Date 2023/5/18 10:51
	 * @params   param
	 * @return com.xinsoft.common.Response<?>
	 **/
	@PostMapping("/pageList")
	public Response<?> pageList(@Valid @RequestBody CusGateWayParam param) {
		return Response.succeed(gatewayService.findPageListByParam(param));
	}

	/**
	 * 导出
	 */
	@PostMapping("/export")
	public Response<?> export(@RequestBody @ApiParam("查询参数") CusGateWayParam param, HttpServletResponse response) throws Exception {
		List<CusGateway> cusGatewayList = gatewayService.findListByParam(param);
		ExcelUtils.exportByEasypoi(cusGatewayList, CusGateway.class, "网关信息", "网关信息", response, "网关信息");
		return Response.succeed();
	}

	/**
	 * 导入
	 */
	@PostMapping("/import")
	@ResponseBody
	public Response<?> importExcel(@RequestParam("file") MultipartFile multipartFile) throws IOException {
		return Response.succeed( gatewayService.importExcel(multipartFile));
	}
}
